<?php

namespace common\models\shop;

use common\models\business\BusinessUser;
use Yii;

/**
 * This is the model class for table "shop_comment".
 *
 * @property integer $id
 * @property integer $userid
 * @property string $openid
 * @property integer $goodsid
 * @property string $content
 * @property integer $star
 * @property integer $createtime
 */
class ShopComment extends \yii\db\ActiveRecord
{


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '商品评论',      //用于修改了什么的显示
        'mainfield' => 'content',      //主要的显示标题的字段
        'picturefield' => ['picture'],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    const STATUS_AGREE = 1;
    const STATUS_DISAGREE = -1;
    const STATUS_NOMAL = 0;
    public static $statues = [
        self::STATUS_AGREE => '通过',
        self::STATUS_DISAGREE => '不通过',
        self::STATUS_NOMAL => '未审核',
    ];



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shop_comment';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['userid','goodsid', 'content', 'star', 'createtime'], 'required'],
            [['userid', 'goodsid', 'star', 'createtime','status'], 'integer'],
            [['openid', 'content'], 'string', 'max' => 255],
            [['picture'], 'image', 'extensions' => 'jpg, jpeg, gif, png','on' => ['insert', 'update']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'userid' => '用户',
            'openid' => '用户openid',
            'goodsid' => '商品',
            'content' => '内容',
            'star' => '星级',
            'createtime' => '评价时间',
            'status' => '状态',
            'picture' => '评价图',
        ];
    }


    public function getuser()
    {
        return $this->hasOne(BusinessUser::className(),['id'=>'userid']);
    }


    public function getGoods()
    {
        return $this->hasOne(ShopGoods::className(),['id'=>'goodsid']);
    }
}
